package com.huixin.zhang.core.page;

import java.util.List;

import com.github.pagehelper.PageInfo;

/**
 * 分页返回结果
 *
 * @author Toltech
 * @date Jan 12, 2019
 */
public class PageResult<T> {
	/**
	 * 当前页码
	 */
	private int pageNum;
	/**
	 * 每页数量
	 */
	private int pageSize;
	/**
	 * 记录总数
	 */
	private long totalSize;
	/**
	 * 页码总数
	 */
	private int pageCount;
	/**
	 * 分页数据
	 */
	private List<T> contents;

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public long getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(long totalSize) {
		this.totalSize = totalSize;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public List<T> getContents() {
		return contents;
	}

	public void setContents(List<T> contents) {
		this.contents = contents;
	}

	public static <T> PageResult<T> createPage(PageRequest pageRequest, PageInfo<T> pageInfo) {
		PageResult<T> pageResult = new PageResult<T>();
        pageResult.setPageNum(pageInfo.getPageNum());
        pageResult.setPageSize(pageInfo.getPageSize());
        pageResult.setTotalSize(pageInfo.getTotal());
        pageResult.setPageCount(pageInfo.getPages());
        pageResult.setContents(pageInfo.getList());
		return pageResult;
	}

}
